
import APIZPZ from "../../../utils/apiZpz";

// pages/home/home.ts
Page({

  /**
   * 页面的初始数据
   */
  data: {
    oldTime: 0,
    phoneNum: undefined,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
  },
  getUserInfo() {
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
      }
    })
  },
  showChooseAddress() {
    const time = new Date().getTime();
    if (time - this.data.oldTime < 1000) {
      return;
    }
    this.data.oldTime = time;
    APIZPZ.getAddressList().then(() => {
      wx.navigateTo({ url: '/pages/address/address-list/address-list' })
    })
  },
  toHelp() {
    wx.navigateTo({ url: '/pages/tabBarPage/mine/help/help' })
  },
  toLogin() {
    const time = new Date().getTime();
    if (time - this.data.oldTime < 1000) {
      return;
    }
    this.data.oldTime = time;
    APIZPZ.getAddressList().then(() => {
    })
  },
  contactService() {
  },
  toOrderList(e: any) {
    const time = new Date().getTime();
    if (time - this.data.oldTime < 1000) {
      return;
    }
    this.data.oldTime = time;
    APIZPZ.getAddressList().then(() => {
      const orderStatus = e.currentTarget.dataset.status || 0;
      wx.navigateTo({ url: `/pages/my-order/order-list/order-list?orderStatus=${orderStatus * 1}` })
    })
  },
  toAgreement(e: any) {
    const url = e.currentTarget.dataset.url;
    wx.navigateTo({ url })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const phoneNum = wx.getStorageSync('phoneNum');
    this.setData({
      phoneNum: phoneNum.replace(/^(\d{3})\d{4}(\d{4})$/, '$1****$2')
    });
    this.getTabBar().setData({
      selectedIndex: 3
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})